<template>
  <div class="approvalRecord">
    <TitleName
      title="审批记录"
      icon="i-carbon-bookmark-filled"
      class="title"
    ></TitleName>
    <el-row class="mt-50px">
      <el-col
        v-for="(o, index) in examineObj"
        :key="o"
        :span="10"
        :offset="index % 2 == 0 ? 2 : 1"
      >
        <el-card
          shadow="hover"
          class="w-100% pointer mb-20px"
          @click="handelClick(o)"
          v-if="o.status != '流程未发起'"
        >
          <el-row class="leading-30px">
            <el-col :span="14">
              <svg-icon
                :icon-class="o.icon"
                class="w-30px h-30px align-middle"
              />
              <span
                class="text-#000 leading-30px ml-10px text-16px font-bold align-bottom"
                >{{ o.businessldsName }}</span
              >
            </el-col>
            <el-col :span="10" class="text-right text-15px">
              <i
                :class="
                  o.status == '审批通过'
                    ? 'h-8px w-8px bg-#fe9400 inline-block rounded'
                    : o.status == '流程未发起'
                    ? 'h-8px w-8px bg-#ccc inline-block rounded'
                    : 'h-8px w-8px bg-#10d070 inline-block rounded'
                "
              ></i>
              {{ o.status }}
            </el-col>
          </el-row>
          <div class="mt-11px text-15px" style="border-top: 1px solid #ccc">
            <p>
              创建人<span class="text-#666 ml-15px">{{ o.createBy }}</span>
            </p>
            <p>
              创建时间<span class="text-#666 ml-15px">{{
                parseTime(o.createTime)
              }}</span>
            </p>
          </div>
        </el-card>
      </el-col>
      <el-empty
        description="暂无数据"
        v-if="examineObj.length == 0 && isShow"
        style="margin: auto"
      ></el-empty>
    </el-row>
  </div>
</template>
<script setup name="ApprovalRecord">
import { useRoute, useRouter } from 'vue-router'
import { reactive, toRefs } from 'vue'
import * as Api from '@/api/projectManage/project'
const router = useRouter()
const { proxy } = getCurrentInstance()
const props = defineProps({
  baseDetail: {
    required: true,
    type: Object || Array,
    default: () => {
      return {}
    }
  },
  biddingDetail: {
    required: true,
    type: Object || Array,
    default: () => {
      return {}
    }
  }
})
const examineObj = ref([]) //项目、投标反馈结果
const isShow = ref(false) //是否显示状态
watch(
  () => props.baseDetail,
  val => {
    if (val && !!location.href.match(/projectDetails/)) {
      getList()
    }
  },
  {
    immediate: true
  }
)
function getList() {
  // 获取项目和投标结果反馈等模块审批状态接口
  let businessldsVal =
    props.baseDetail.projectId +
    (props.biddingDetail.bid ? ',' + props.biddingDetail.bid : '') +
    (props.baseDetail.ConclusionId ? ',' + props.baseDetail.ConclusionId : '')
  Api.getProStatusByBusinessIds(businessldsVal)
    .then(res => {
      examineObj.value = []
      res.data.forEach(item => {
        if (item.status != '流程未发起') {
          if (item.category == 0) {
            //项目申请
            examineObj.value.push({
              ...item,
              businessldsName: '项目创建审批',
              businesslds: props.baseDetail.projectId,
              icon: 'svg_xmcj',
              processed: item.taskId ? true : false
            })
          } else if (item.category == '30') {
            //项目完结-结项
            examineObj.value.push({
              ...item,
              businessldsName: '项目完结审批',
              businesslds: props.baseDetail.projectId,
              icon: 'svg_xmjxfq',
              processed: item.taskId ? true : false
            })
          } else {
            //投标情况反馈
            examineObj.value.push({
              ...item,
              businessldsName: '投标情况反馈',
              businesslds: props.biddingDetail.bid || '',
              icon: 'svg_tbfk',
              processed: item.taskId ? true : false
            })
          }
        }
      })
      isShow.value = true
      console.log(examineObj.value, 'examineObj--')
    })
    .catch(e => {
      isShow.value = true
    })
}
/** 点击调整详情页 */
const handelClick = row => {
  console.log(row, 'row--')
  if (row.status == '流程未发起') {
    if (
      row.businessldsName == '项目创建审批' ||
      row.businessldsName == '项目完结审批'
    ) {
      router.push({
        path: '/sales/projectManage/editProject',
        query: { id: row.businesslds }
      })
    } else {
      router.push({
        path: '/sales/projectManage/biddingResults',
        query: { id: row.businesslds }
      })
    }
  } else {
    router.push({
      path: '/process/workDetail',
      query: {
        procInsId: row.proInsId, //发起流程的id
        taskId: row.taskId, //任务id(每个环节审批人的任务id)
        processed: row.processed, //这个是判断是否是已办待办
        isCirculation: row.status == '审批通过' ? true : false
      }
    })
  }
}
</script>
